<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>权益管理</cite></a>
    <a><cite>权益兑换码</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layadmin-search">
      <form class="layui-form" method="post" lay-filter="form_keys_search">
        <script type="text/html" template>
          <div class="layui-inline">
            <div class="layui-form-label">关键字搜索</div>
            <div class="layui-input-inline">
              <input type="text" name="keyword" value="{{decodeURIComponent(layui.router().search.keyword || '')}}"
                     class="layui-input"
                     placeholder="请输入存证ID/权益码">
            </div>
          </div>
          <div class="layui-inline layui-btn-group">
            <button type="submit" lay-submit class="layui-btn" lay-filter="submit_keys_search">
              <i class="layui-icon layui-icon-search"></i>查询
            </button>
            <button type="submit" lay-submit class="layui-btn layui-btn-warm"
                    lay-filter="reset_keys_search">
              <i class="layui-icon layui-icon-close"></i>重置
            </button>
          </div>
        </script>
      </form>
    </div>
    <div class="layui-card-body">
      <div id="table_keys"></div>
      <script type="text/html" id="tpl_asset_user">
        {{d.asset.user.mobile}}
      </script>
      <script type="text/html" id="tpl_asset_token_id">
        {{d.asset.token_id}}
      </script>
      <script type="text/html" id="tpl_asset_status">
        {{d.asset.asset_status.description}}
      </script>
      <script type="text/html" id="tpl_status">
        {{# if (d.status.value === 'used') { }}
        <span class="layui-font-gray">{{d.status.description}}</span>
        {{# } }}
        {{# if (d.status.value === 'not_use') { }}
        <span class="layui-font-green">{{d.status.description}}</span>
        {{# } }}
      </script>
    </div>
  </div>
</div>

<script>
  layui.use(['fox_table'], function () {
    let $ = layui.$
      , fox_table = layui.fox_table
      , form = layui.form

    let resourceUrl = 'agent-admin/asset_keys'

    // 列表查询
    fox_table.render({
      id: 'table_keys'
      , url: resourceUrl
      , cols: [[
        {title: 'ID', field: 'id', width: 80, align: "center", sort: true}
        , {title: '资产存证ID', templet: '#tpl_asset_token_id', minWidth: 100}
        , {title: '权益码', field: 'key', width: 150}
        , {title: '原权益码', field: 'prev_code', width: 150}
        , {title: '持有者', templet: '#tpl_asset_user', width: 150}
        , {title: '生成时间', field: 'created_at', width: 180}
        , {title: '资产状态', templet: '#tpl_asset_status', width: 100}
        , {title: '权益码状态', templet: '#tpl_status', width: 150, align: "center"}
      ]]
    });

    //搜索
    form.on('submit(submit_keys_search)', function (d) {
      fox_table.reload(d.field);
      return false;
    });
    //重置
    form.on('submit(reset_keys_search)', function (d) {
      $("input[name='keyword']").val('');
      fox_table.reload({});
      return false;
    });
  })
</script>

